package co.yixiang.modules.shop.rest.Arest;

import co.yixiang.modules.shop.domain.YxStoreCart;
import co.yixiang.modules.shop.service.YxStoreCartService;
import co.yixiang.modules.shop.service.YxStoreProductAttrValueService;
import co.yixiang.modules.shop.service.YxStoreProductService;
import co.yixiang.modules.shop.service.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "Api2:商城:购物车")
@RestController
@RequestMapping("api2/yxStoreCart")

public class AStoreCartController extends ABaseController  {

    @Autowired
    public YxStoreCartService yxStoreCartService;

    //sku表
    @Autowired
    public YxStoreProductAttrValueService storeProductAttrValueService;

    @Autowired
    public YxStoreProductService yxStoreProductService;

    private final String ERR_MSG_TPL = "{}不能为空或null";


    @ApiOperation(value = "加入购物车")
    @PostMapping("/add")
    public ResponseEntity addToCart(@Validated @RequestBody YxStoreCart cart ){
        yxStoreCartService.save(cart);
        return ResponseEntity.ok(cart);
    }



    @ApiOperation(value = "获取购物车内容")
    @GetMapping(value = "/")
    public ResponseEntity getYxStoreProducts(YxStoreCartQueryCriteria criteria) {
        List<ShopCartDto> cartItem = yxStoreCartService.getOnesCartItems(criteria.getUid());
        return ResponseEntity.ok(cartItem);
    }



    // @ApiOperation(value = "更改商品选中状态")
    // @PostMapping(value = "/{id}")
    // public ResponseEntity buy(@PathVariable Integer id, @ApiParam(value = "true选中，false不选中") Boolean checked) {
    //     YxStoreCart one = yxStoreCartService.getById(id);
    //     if(checked){
    //         one.setIsNew(1);
    //     }else{
    //         one.setIsNew(0);
    //     }
    //     yxStoreCartService.updateById(one);
    //     return new ResponseEntity(HttpStatus.OK);
    // }

    @ApiOperation(value = "获取预提交商品列表")
    @GetMapping("/preSubmit")
    public ResponseEntity preSubmit(YxStoreCartQueryCriteria criteria) {
        List<YxStoreCartDto> res = yxStoreCartService.listPreSubmit(criteria);
        return new ResponseEntity(res,HttpStatus.OK);
    }




}
